package com.yanqu.road.server.cmd.monopolymarket.fortress;

import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.pb.monopolymarket.MonopolyMarketProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

/**
 * @Description
 * @Author cwq
 * @Data 2021/10/15 16:32
 */
@Cmd(code = GameProtocol.S_MONOPOLY_MARKET_FORTRESS_RECEIVE_COLLECT_REWARD_FROM_CROSS, desc = "边关要塞 领取采集奖励 跨服返回区服 协议")
public class MonopolyMarketFortressReceiveCollectRewardFromCrossCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        MonopolyMarketProto.MonopolyMarketResGrabReceiveRewardToGameServerMsg msg = MonopolyMarketProto.MonopolyMarketResGrabReceiveRewardToGameServerMsg.parseFrom(packet.getBytes());
        for(MonopolyMarketProto.MonopolyMarketFortressTipEntity item :  msg.getFortressTipList()){
            Property property = PropertyHelper.parseStringToProperty(item.getReward());
            player.getModule(CurrencyModule.class).addCurrency(property, eLogMoneyType.MonopolyMarket,eLogMoneyType.MonopolyMarketFortressReceiveCollectReward);
        }

        MonopolyMarketProto.BroadcastMonopolyMarketRespMsg.Builder builder = MonopolyMarketProto.BroadcastMonopolyMarketRespMsg.newBuilder();
        builder.setType(5);
        builder.addAllFortressTip(msg.getFortressTipList());
        player.sendPacket(YanQuMessageUtils.buildMessage(ClientProtocol.U_MONOPOLY_MARKET_BROADCAST, builder));
    }

    @Override
    public void sendData(GamePlayer player) {
    }

}
